home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.03 Mar 91 / SAY() / Speech.c next >
Encoding:
C/C++ Source or Header  |  1988-11-14  |  2.0 KB  |  60 lines  |  [TEXT/KAHL]

  1. /* Speech.c -- QB code resource for access to MacinTalk routines 
  2.    Copyright (C)1988 by William H. Ball for MacTutor™ magazine
  3.     
  4.    Usage: SAY(rate,pitch,string) 
  5.    where  [rate] is an integer or integer variable 
  6.              [pitch] is an integer or integer variable 
  7.              [string] is a string variable or string enclosed by quotes. 
  8.    for example,
  9.           hefty% = 100 : wimpy% = 300 : fast% = 200 : slow% = 100
  10.           m$ = "Hello there"
  11.           CALL SAY(slow%,hefty%,m$)
  12.           CALL SAY(fast%,wimpy%,m$)         
  13.                       or                      
  14.           CALL SAY(100,100,"Hello there")
  15.           CALL SAY(200,300,"Hello there")
  16.           
  17.     Caveats: Can cause bombs of ID 2 or ID 10 if you fail to pass 
  18.              the correct number or type of arguments.
  19. */
  20.  
  21. #include "Macintalk.h"                        /* LSC's header                */
  22. #include "BasicLSC.h"                        /* supplied with QB            */
  23.     
  24. PUBLIC VOID main()                            /* see QB manual p. 448        */
  25. {
  26. SpeechErr     err;                            /* error code                */
  27. SpeechHandle theSpeech;                        /* pointer to speech        */
  28. Handle spOut;                                /* speech handle            */
  29.  
  30. INT16        TempFlag,len,type,rate,pitch;    /* INT16 == short            */
  31. StringPtr     message;                        
  32. LIBARGPTR    valptr;
  33.  
  34.     SAVEREGS();                    /* Save BASIC's A4 and A5 registers        */
  35.     
  36.     if ((err = SpeechOn("", &theSpeech)) != noErr) { return; }
  37.         
  38.     if ((type = GetNextLibArg(&valptr,&TempFlag)) != _INTARG) rate = 150;
  39.     else rate = IntegerArg();
  40.     SpeechRate(theSpeech,(int)rate);
  41.      
  42.     if ((type = GetNextLibArg(&valptr,&TempFlag)) != _INTARG) pitch = 95;
  43.     else pitch = IntegerArg();
  44.     SpeechPitch(theSpeech,(int)pitch,Natural);
  45.     
  46.     type = GetNextLibArg(&valptr,&TempFlag);
  47.     if (type != _NULLARG) {
  48.         if (type == _STRGARG) {
  49.             if (TempFlag)
  50.                 FreeTempDesc((SDRECPTR)valptr);
  51.             LoadStringDesc((SDRECPTR)valptr,&message,&len);
  52.             spOut = NewHandle(0L);        /* allocate handle */
  53.             Reader(theSpeech,message,(long)len,spOut);
  54.             MacinTalk(theSpeech, spOut);
  55.             SpeechOff(theSpeech);
  56.             DisposHandle(spOut);
  57.         } 
  58.     }
  59.     RESTREGS();            /* Restore BASIC's A4 and A5 registers    */
  60. }